//
//  DSZGZMoreCollectionViewCell.m
//  7.13苏宁框架
//
//  Created by app15 on 15/7/19.
//  Copyright (c) 2015年 lovena. All rights reserved.
//

#import "DSZGZMoreCollectionViewCell.h"
#import "DSZGZMoreTableViewCell.h"
#import "DSZTJGroupModel.h"
#import "DSZTJSuperModel.h"
#import "UIImageView+WebCache.h"
#import "DSZGZDRViewController.h"
#import "DSZGZXQViewController.h"

@interface  DSZGZMoreCollectionViewCell()
{
    DSZTJSuperModel *GZmodel;
}
@property(nonatomic,retain)NSArray *groupModelArray;
@end

@implementation DSZGZMoreCollectionViewCell

+(NSString*)xib{

    return @"DSZGZMoreCollectionViewCell";
}


-(void)groupModel:(NSArray*)group model:(DSZTJSuperModel*)model{
    _superImageView.userInteractionEnabled=YES;
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tap:)];
    //tap.numberOfTapsRequired = 2;
    [self.superImageView addGestureRecognizer:tap];
    _groupModelArray=group;
    GZmodel=model;
}


- (void)tap:(UITapGestureRecognizer *)tapGetrue {
    DSZGZDRViewController *view=[[DSZGZDRViewController alloc]init];
    [view Drgroupmode:_groupModelArray model:GZmodel];
        if ([self.delegate respondsToSelector:@selector(nextView)]) {
            [_delegate nextView];
        }
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (_groupModelArray.count<=3) {
        return _groupModelArray.count;
    }else{
        return 3;
    }
    
}
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    _tableView.separatorStyle=0;
    static NSString *IDS=@"cell";
    DSZTJGroupModel *model=_groupModelArray[indexPath.row];
    DSZGZMoreTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:IDS];
    if (cell==nil) {
        cell=[[DSZGZMoreTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:IDS];
    }
    cell.selectionStyle=0;
    [cell.groupImageView setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@",model.image]]];
    NSInteger i=model.name.length;
    if (i*15>95) {
        cell.groupTitleLabel.frame=CGRectMake(cell.groupTitleLabel.frame.origin.x, cell.groupTitleLabel.frame.origin.y, 80, cell.groupTitleLabel.frame.size.height);
        cell.vipimage.frame=CGRectMake(cell.groupTitleLabel.frame.origin.x+90, cell.vipimage.frame.origin.y, 12, 12);
    }else{
        cell.groupTitleLabel.frame=CGRectMake(cell.groupTitleLabel.frame.origin.x, cell.groupTitleLabel.frame.origin.y, i*15, cell.groupTitleLabel.frame.size.height);
        cell.vipimage.frame=CGRectMake(cell.groupTitleLabel.frame.origin.x+i*15+10, cell.vipimage.frame.origin.y, 12, 12);
    }
    
    
    cell.groupTitleLabel.text=model.name;
    cell.groupIntorLabel.text=model.intor;
    return cell;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 50;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    DSZGZXQViewController *view=[[DSZGZXQViewController alloc]init];
    DSZTJGroupModel *model=_groupModelArray[indexPath.row];
    [view XqGroupModel:model];
    if ([self.delegate respondsToSelector:@selector(detailView)]) {
        [_delegate detailView];
    }
    
}


@end
